package com.nf.controller.home;

import com.google.gson.Gson;
import com.nf.controller.BaseServlet;
import com.nf.dao.OrderInfoDao;
import com.nf.dao.impl.OrderInfoDaoImpl;
import com.nf.entity.OrderInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 编写servlet，实现根据订单状态 查询未付款的订单
 */
@WebServlet("/api/SelectOrderByStatusServlet.do")
public class SelectOrderByStatusServlet extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

//        SeatService seatService = new SeatServiceImpl();
//        seatService.queRenZuoWei();

        //1.cunzai

        //2.chanchu ding dan

        //3.chanchu zhuangtai

        //4.tian jia xin zhuangtai

        //5.sheng chen xin ding dan

        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();

        OrderInfoDao dao=new OrderInfoDaoImpl();
        OrderInfo order= dao.selectBystatus();

        // 查询有没有未付款的订单，如果有，删除未付款的订单
        if(order!=null){
            dao.del(order.getOrderId());
            out.print(new Gson().toJson(successJson("1")));
        }else{
            out.print(new Gson().toJson(errorJson("2")));
        }

        out.flush();
        out.close();
    }
}
